#include "lgraph.h"
#include <QDebug>
LGraph::LGraph(QWidget *parent,int num,int way):Graph(parent,num)
{
    model=new LModel(num);
    switch(way) //根据way值选择点输入方式
    {
        case 0: //手动输入

        break;
        case 1: //自动生成
            getRandomMap();
        break;
        case 2: //选择文件
            loadGraphFromFile();
        break;
    }
    renderPaint();
}

void LGraph::putArrow()
{
    for(int i=0;i<num;i++)
    {
        for(QList<LModel::Edge>::iterator iter=((LModel*)model)->edges[i].begin();iter!=((LModel*)model)->edges[i].end();iter++)
        {
            LModel::Edge edg=*iter;
            arrowList.push_back(Arrow(i,edg.next,edg.length,Qt::yellow));
        }
    }
}

void LGraph::saveModel()
{
    history.push(model);
    model=new LModel(*((LModel*)model));
}

void LGraph::saveEdge(QTextStream &out)
{
    for(int i=0;i<num;i++)  //遍历所有点
    {
        for(QList<LModel::Edge>::iterator iter=((LModel*)model)->edges[i].begin();iter!=((LModel*)model)->edges[i].end();iter++)
        {
            LModel::Edge edg=*iter;
            out<<i<<"\t"<<edg.next<<endl;
        }
    }
}

LGraph::~LGraph()
{
    delete model;
}
